//
//  MQNavigationController.swift
//  SinaWeiBo
//
//  Created by 毛强 on 16/1/12.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class MQNavigationController: UINavigationController {
//    override func viewDidLoad() {
//        super.viewDidLoad()
//    }
//    override func didReceiveMemoryWarning() {
//        super.didReceiveMemoryWarning()
//    }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0{
            var backTitle = "返回"
            if childViewControllers.count == 1{
                
                backTitle = childViewControllers.first!.title ?? "返回"
            }
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backTitle, target: self, action: "back")
            
            viewController.hidesBottomBarWhenPushed = true
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func back(){
//        dismissViewControllerAnimated(true, completion: nil)
        popViewControllerAnimated(true)
    }
}
